﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Soft
{

    /// <summary>
    /// 错误信息
    /// </summary>
    [Serializable]
    public struct ErrorMessage : ISerializable, IErrorMessage
    {

        public ErrorMessage(int code, string message)
        {
            this.Code = code;
            this.Message = message;
        }


        public ErrorMessage(SerializationInfo info, StreamingContext context)
        {
            this.Code = 0;
            this.Message = string.Empty;
            try
            {
                this.Code = info.GetInt32("Code");
                this.Message = (string)info.GetValue("Message", typeof(string));
            }
            catch
            {
            }
        }


        /// <summary>
        /// 错误码
        /// </summary>
        public int Code { get; private set; }


        /// <summary>
        /// 错误信息
        /// </summary>
        public string Message { get; private set; }


        /// <summary>
        /// 序列化信息
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Code", this.Code);
            info.AddValue("Message", this.Message, typeof(string));
        }



    }
}
